var app = getApp()
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    height:0,
    width:0,
    datalist:[],
    lon:'',
    lat:'',
    info:{},
    markers: [{
      iconPath: "/assets/index_06.png",
      id: 0,
      latitude: 23.099994,
      longitude: 113.324520,
      width: 30,
      height: 30
    }, {
      iconPath: "/assets/index_06.png",
      id: 1,
      latitude: 23.099994,
      longitude: 113.334522,
      width: 50,
      height: 50
    }],
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/map/map?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  markertap(e) {
    console.log(e.markerId)
    if(e.markerId){
      app.ajax("map_info", { id: e.markerId}, (data) => {
        if(data.data.data){
          let infos = {}
          infos.address = data.data.data.address
          infos.contact_user = data.data.data.contact_user
          infos.total_num = data.data.data.total_num
          infos.phone = data.data.data.phone,
          infos.department_name = data.data.data.department_name
          this.setData({
            info:infos
          })
        }
      })
    }
  },
  onLoad: function (options) {
    var that = this;
    console.log(wx.getStorageSync('rd_session'))

    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({
          width: res.windowWidth,
          height: res.windowHeight
        })
      }
    })
    app.ajax("map",{},(data) => {
      if(data.data.list.length>0){
        let arr = []
        arr = data.data.list
        let markarr = []
        for(let item of arr){
          let mark = {}
          mark.iconPath = "/assets/index_06.png"
          mark.id = item.id
          mark.latitude = item.latitude
          mark.longitude = item.longitude
          mark.width = 50
          mark.height = 50
          markarr.push(mark)
        }
        let infos = {}
        infos.address = data.data.list[0].address
        infos.contact_user = data.data.list[0].contact_user
        infos.total_num = data.data.list[0].total_num
        infos.phone = data.data.list[0].phone
        infos.department_name = data.data.list[0].department_name
        this.setData({
          datalist: data.data.list,
          markers:markarr,
          lon: data.data.list[0].longitude,
          lat: data.data.list[0].latitude,
          info: infos
        })
        console.log(markarr)
      }
    })

  },
})
